﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Microsoft.WindowsAzure;

namespace BareWeb.FluentAzureDiagnostics
{
    [TestClass]
    public class PerformanceCountersTest
    {
        [TestMethod]
        public void WithPerformanceCounter_Adds()
        {
            var target = new DiagnosticsCapture(CloudStorageAccount.DevelopmentStorageAccount);

            var expected = 1;
            var actual = target.Default().WithPerformanceCounter(@"\\comp\counter", TimeSpan.FromDays(1.4D))
                .Configuration.PerformanceCounters.DataSources.Count;

            Assert.AreEqual(expected, actual);
        }

        [TestMethod]
        public void WithPerformanceCounter_AddsMany()
        {
            var target = new DiagnosticsCapture(CloudStorageAccount.DevelopmentStorageAccount);

            var expected = 3;
            var actual = target.Default()
                .WithPerformanceCounter(@"\\comp\cpu", TimeSpan.FromDays(1.4D))
                .WithPerformanceCounter(@"\\comp\memory", TimeSpan.FromDays(1.5D))
                .WithPerformanceCounter(@"\\comp\aspnet_blah", TimeSpan.FromDays(1.6D))
                .Configuration.PerformanceCounters.DataSources.Count;

            Assert.AreEqual(expected, actual);
        }

        [TestMethod]
        public void PerformanceCountersScheduledTransfer_Reflected()
        {
            var target = new DiagnosticsCapture(CloudStorageAccount.DevelopmentStorageAccount);

            var expected = TimeSpan.FromDays(1337D);

            var actual = target.Default()
                .TransferPerformanceCountersEvery(expected)
                .Configuration.PerformanceCounters.ScheduledTransferPeriod;

            Assert.AreEqual(expected, actual);
        }

        [TestMethod]
        public void PerformanceCountersQuota_Reflected()
        {
            var target = new DiagnosticsCapture(CloudStorageAccount.DevelopmentStorageAccount);

            var expected = 1337;

            var actual = target.Default()
                .WithPerformanceCountersBufferQuotaInMBOf(expected)
                .Configuration.PerformanceCounters.BufferQuotaInMB;

            Assert.AreEqual(expected, actual);
        }
    }
}
